﻿using System;
using System.IO;
using System.Reflection;
using System.Text;
using Blader.UI.Win32;

namespace Blader.Config
{
    public class IniFile
    {
        private static readonly IniFile instance = new IniFile();
        public string path;

        private IniFile()
        {
            path = Path.Combine(GetBaseDirectory(), "Blader.ini");
        }

        public static IniFile Instance
        {
            get { return instance; }
        }

        private string GetBaseDirectory()
        {
            return Path.GetDirectoryName(new Uri(Assembly.GetExecutingAssembly().GetName().CodeBase).LocalPath);
        }

        public void IniWriteValue(string section, string key, string value)
        {
            Native.WritePrivateProfileString(section, key, value, path);
        }

        public string IniReadValue(string section, string key)
        {
            var temp = new StringBuilder(255);
            int i = Native.GetPrivateProfileString(section, key, "", temp, 255, path);
            return temp.ToString();
        }
    }
}